package com.enation.app.shop.front.api.utils;

import com.enation.framework.database.IDaoSupport;
import com.enation.framework.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Random;

public class SnUtil {
    @Autowired
    private IDaoSupport daoSupport;


    private String createSn(){
        boolean isHave = true;  //数据库中是否存在该订单
        String sn = "";			//订单号

        //如果存在当前订单
        while(isHave) {
            StringBuffer  snSb = new StringBuffer(DateUtil.getDateline()+"") ;
            snSb.append(new Random().nextInt(100-10)+10);
            String sql = "SELECT count(order_id) FROM es_order WHERE sn = '" + snSb.toString() + "'";
            int count = this.daoSupport.queryForInt(sql);
            if(count == 0) {
                sn = snSb.toString();
                isHave = false;
            }
        }
        return sn;
    }

}
